package org.flashbrighton.as3bots.display.templates
{
	import flash.display.Sprite;
	import flash.filters.DropShadowFilter;
	import flash.text.TextField;
	import flash.text.TextFieldAutoSize;
	import flash.text.TextFormat;
	import flash.text.TextFormatAlign;

	public class LoadBotTemplate extends Sprite
	{
		
		
		public var libraryBotsContainer : Sprite = new Sprite();
		public var selectedBotsContainer : Sprite = new Sprite();
		public var championsBotsContainer : Sprite = new Sprite();
		public var loadButton:Sprite=new Sprite();
		public var startButton : Sprite = new Sprite();
		public var container : Sprite = new Sprite();
		public var debugTextField : TextField = new TextField();
		
		public function LoadBotTemplate( width : Number , height : Number )
		{
			var margin : Number = 15;
			container.graphics.lineStyle( 1, 0x30d030 );
			container.graphics.beginFill( 0x308030 );
			container.graphics.drawRoundRect( 0 , 0, 720,480, 20,20 );
			container.graphics.endFill();
			container.graphics.beginFill( 0x202020, 1 );
			container.graphics.drawRoundRect( margin , margin, 720 - 2*margin, 480 - 2*margin,10,10 );
			container.graphics.endFill();

			container.x = width /2 - container.width / 2;
			container.y = height / 2 - container.height / 2;


			createTextLabel( 2*margin + 60, margin + 10, 'Availible bots' );
			createTextLabel( margin + 280, margin + 10, 'Chosen bots' );
			createTextLabel( margin + 500, margin + 10, 'Champions' );


			libraryBotsContainer.x = margin + 20;
			libraryBotsContainer.y = margin + 40;
			drawBox( libraryBotsContainer );
			
			selectedBotsContainer.x = margin + 240;
			selectedBotsContainer.y = margin + 40;
			drawBox( selectedBotsContainer );

			championsBotsContainer.x = margin + 460;
			championsBotsContainer.y = margin + 40;
			drawBox( championsBotsContainer );

			var loadLabel : TextField = new TextField();
			var tformat:TextFormat = new TextFormat("Arkitech", 12, 0x0);
			tformat.align = TextFormatAlign.CENTER;
			loadLabel.embedFonts = true;
			loadLabel.defaultTextFormat = tformat;
			loadLabel.autoSize = TextFieldAutoSize.LEFT;
			loadLabel.text = 'load bot from file';

			var startLabel : TextField = new TextField();
			startLabel.embedFonts = true;
			tformat = new TextFormat("Arkitech", 22, 0x0);
			startLabel.defaultTextFormat = tformat;
			startLabel.width = 120;
			startLabel.height = 30
			startLabel.text = 'start';
			
			loadButton.buttonMode=true;
			loadButton.graphics.beginFill(0xa0a0a0)
			loadButton.graphics.drawRoundRect(0,0,loadLabel.width,20,5,5);
			loadButton.graphics.endFill();
			loadButton.filters=[new DropShadowFilter()];
			loadButton.addChild( loadLabel );
			loadButton.mouseChildren = false;
			loadButton.x = margin + 20;
			loadButton.y = libraryBotsContainer.getBounds( this ).bottom + margin;
			
			startButton.buttonMode=true;
			startButton.graphics.beginFill(0xa0a0a0)
			startButton.graphics.drawRoundRect(0,0,123,30,5,5);
			startButton.graphics.endFill();
			startButton.filters=[new DropShadowFilter()];
			startButton.addChild( startLabel );
			startButton.mouseChildren = false;
			startButton.x = container.width - startButton.width - 2*margin;
			startButton.y = container.height - startButton.height - 2*margin;

			debugTextField.multiline = true;
			debugTextField.border = true;
			debugTextField.defaultTextFormat = new TextFormat("Arkitech", 12, 0xa0a0a0 );
			debugTextField.borderColor = 0xa0a0a0;
			debugTextField.width = container.width - 4*margin;
			debugTextField.height = 100;
			debugTextField.x = 2*margin;
			debugTextField.y = 300;

			addChild( container );
			container.addChild( debugTextField );
			container.addChild( loadButton );
			container.addChild( startButton );
			container.addChild( libraryBotsContainer );
			container.addChild( selectedBotsContainer );
			container.addChild( championsBotsContainer );
			
			
		}
		
		protected function createTextLabel( x : Number , y : Number , s : String ):void
		{
			var tformat:TextFormat = new TextFormat("Arkitech", 12, 0xffffff);
			tformat.align = TextFormatAlign.CENTER;
			var textField : TextField = new TextField();
			
			textField.defaultTextFormat = tformat;
			textField.x = x;
			textField.y = y;
			textField.embedFonts = true;
			textField.mouseEnabled = false;
			textField.autoSize = TextFieldAutoSize.CENTER;
			textField.text = s;
			container.addChild( textField );
			
			
		}
		
		protected function drawBox( container : Sprite ):void
		{
			container.graphics.lineStyle( 0 );
			container.graphics.beginFill( 0x404040, 0.8 );
			container.graphics.drawRect( 0 , 0, 200, 200 );
			container.graphics.endFill();
			
		}
		
		
	}
}